﻿package mortal.game.view.arena.view
{
    import com.mui.events.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.component.window.*;
    import mortal.game.manager.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.view.common.*;
    import mortal.game.view.wizard.*;

    public class ArenaMainWindow extends BaseWindow
    {
        private var _tabBar:GTabarNew;
        private var _pageTabData:Array;
        private var _currentPanel:ArenaPanelBaseNew;
        private var _rect3d:Rect3DObject;
        private var _dicIndexClass:Dictionary;
        private static var _instance:ArenaMainWindow;

        public function ArenaMainWindow(param1:ExceptionClass)
        {
            this._dicIndexClass = new Dictionary();
            this.initTabData();
            super(LayerManager.windowLayer3D);
            setSize(910 - 4, 601 - 8);
            title = Language.getString(40813);
            return;
        }// end function

        private function initTabData() : void
        {
            this._pageTabData = Language.getArray(40500);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._tabBar = UIFactory.gTabBarNew(3, 30 + 2, this._pageTabData, 910 - 7, 497 - 3, 85, 26, this, this.onTabBarChange, "TabButtonNew");
            this._tabBar.selectedIndex = 0;
            this._dicIndexClass[0] = ArenaSignUpPanel;
            this._dicIndexClass[1] = ArenaCurrServerRankPanelNew;
            this._dicIndexClass[2] = ArenaRegionRankPanelNew;
            this._dicIndexClass[3] = ArenaCurrHistRankPanelNew;
            this._dicIndexClass[4] = ArenaRegionHisRankPanelNew;
            this.onTabBarChange();
            this.init3DRect();
            return;
        }// end function

        protected function init3DRect() : void
        {
            if (this._rect3d == null)
            {
                this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(0, 0, 0, 0), this);
                Rect3DManager.instance.windowShowHander(null, this);
            }
            return;
        }// end function

        private function onTabBarChange(event:MuiEvent = null) : void
        {
            var _loc_2:* = UICompomentPool.getUICompoment(this._dicIndexClass[this._tabBar.selectedIndex]);
            if (_loc_2 != this._currentPanel)
            {
                if (this._currentPanel)
                {
                    this._currentPanel.dispose();
                }
                if (_loc_2.isDisposed)
                {
                    _loc_2.createDisposedChildren();
                }
                this.addChild(_loc_2);
                this._currentPanel = _loc_2;
            }
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show();
            ArenaSettleRuleWinNew.instance.show();
            ArenaSettleRuleWinNew.instance.openPanelByTab(2);
            LayerManager.windowLayer.centerWindows(this, ArenaSettleRuleWinNew.instance);
            return;
        }// end function

        override protected function onMouseMoveHandler(event:MouseEvent) : void
        {
            super.onMouseMoveHandler(event);
            if (ArenaSettleRuleWinNew.isViewShow)
            {
                ArenaSettleRuleWinNew.instance.x = this.x + this.width + 5;
                ArenaSettleRuleWinNew.instance.y = this.y;
            }
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            if (ArenaSettleRuleWinNew.isViewShow)
            {
                LayerManager.windowLayer.centerWindows(this, ArenaSettleRuleWinNew.instance);
            }
            return;
        }// end function

        override protected function onWindowDownHandler(event:MouseEvent) : void
        {
            super.onWindowDownHandler(event);
            if (ArenaSettleRuleWinNew.isViewShow)
            {
                ArenaSettleRuleWinNew.instance.layer.setTop(ArenaSettleRuleWinNew.instance);
            }
            return;
        }// end function

        public function get currentPanel() : ArenaPanelBaseNew
        {
            return this._currentPanel;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._tabBar.dispose(param1);
            if (this._currentPanel)
            {
                this._currentPanel.dispose(param1);
            }
            this._tabBar = null;
            this._currentPanel = null;
            if (ArenaSettleRuleWinNew.isViewShow)
            {
                ArenaSettleRuleWinNew.instance.hide();
            }
            if (this._rect3d)
            {
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
            }
            return;
        }// end function

        public static function get instance() : ArenaMainWindow
        {
            if (!_instance)
            {
                _instance = new ArenaMainWindow(new ExceptionClass());
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

        public static function isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}

class ExceptionClass extends Object
{

    function ExceptionClass()
    {
        return;
    }// end function

}

